//
//  KeyboardBottomBar.m
//  YunWu
//
//  Created by 古俊杰 on 2016/10/21.
//  Copyright © 2016年 曲虹亮. All rights reserved.
//

#import "KeyboardBottomBar.h"

#import "YWItemButton.h"

@interface KeyboardBottomBar ()

@property (weak, nonatomic) IBOutlet YWItemButton *showBtn;

@property (weak, nonatomic) IBOutlet UIButton *phoneCallBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineHeightConstraint;

@end

@implementation KeyboardBottomBar

+(KeyboardBottomBar *)instanceKeyboardBottomBar
{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"KeyboardBottomBar" owner:nil options:nil];
    return [nibView objectAtIndex:0];
}

-(void)updateConstraints
{
    [super updateConstraints];
    
    self.lineHeightConstraint.constant = 0.5f;
}

-(void)awakeFromNib
{
    [super awakeFromNib];
    
    [self.showBtn setAdjustsImageWhenHighlighted:NO];

}

-(void)setKeyBoardHidden:(BOOL)keyBoardHidden
{
    _keyBoardHidden = keyBoardHidden;
    
    self.showBtn.selected =!keyBoardHidden;
}

-(void)setPhoneCallBtnHidden:(BOOL)phoneCallBtnHidden
{
    _phoneCallBtnHidden = phoneCallBtnHidden;
    
    self.phoneCallBtn.hidden = phoneCallBtnHidden;
}

- (IBAction)gotoContact:(id)sender
{
    if (self.gotoContact) {
        self.gotoContact();
    }
}


- (IBAction)callAction:(id)sender
{
    UIButton *button = (UIButton *)sender;
    
    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSth:) object:button];
    [self performSelector:@selector(doSth:) withObject:button afterDelay:0.1f];
    
}

- (void)doSth:(id)sender
{
    if (self.callAction) {
        self.callAction();
    }
}

- (IBAction)showKeyboard:(UIButton *)sender
{
    sender.selected = !sender.isSelected;
    
    if (self.showKeyboard) {
        self.showKeyboard(sender.selected);
    }
}

- (IBAction)videoCallAction:(UIButton *)sender
{
    if (self.videoCallAction) {
        self.videoCallAction();
    }
}






@end
